package cn.org.channl.session;

import io.netty.channel.Channel;
import java.util.HashMap;
import java.util.Map;

/**
 * 已经登陆的客户端需要保持会话信息
 * 
 * @author weijia
 */
public class ConnectorManager{
	//保证单例
	public static final ConnectorManager connectorManager = new ConnectorManager();

	private ConnectorManager() {
		super();
	}

	private Map<String,Channel> map = new HashMap<>();

	
	public Channel get(String key){
		return map.get(key);
	}
	
	public void add(String key,Channel channel){
		map.put(key, channel);
	}
	
	public void remove(String key){
		map.remove(key); 
	}

	public void remove(Channel channel){
		String targetKey = null;
		for(String key:map.keySet()){
			Channel valueChannel = map.get(key);
			if(channel  == valueChannel){
				targetKey = key;
				break;
			}
		}
		if(targetKey != null){
			map.remove(targetKey);
		}
	}
	
	
}
